//
//  AccountDetails2TableViewController.m
//  PlayerWorld
//
//  Created by 1 on 16/5/12.
//  Copyright © 2016年 刘成. All rights reserved.
//

#import "AccountDetails2TableViewController.h"
#import "AccountDetailsTableViewCell.h"
#import "UIKit+AFNetworking.h"
#import "M_L_Object.h"
@interface AccountDetails2TableViewController ()

@end

@implementation AccountDetails2TableViewController
{
    NSMutableArray *_listArray;
}
-(void)obtainData
{
    // 启动系统风火轮
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
    //服务器给的域名
    NSString *domainStr = @"http://666.lefun6.com/";
    
    //创建一个可变字典
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    //往字典里面添加需要提交的参数
    [parametersDic setObject:@"User" forKey:@"Model"];
    [parametersDic setObject:@"DetailsOfFunding_List" forKey:@"Action"];
    [parametersDic setObject:@"1000" forKey:@"pagenum"];
    [parametersDic setObject:@"1" forKey:@"showpagenum"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    //以post的形式提交，POST的参数就是上面的域名，parameters的参数是一个字典类型，将上面的字典作为它的参数
    [manager POST:domainStr parameters:parametersDic progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 解析成功隐藏系统风火轮
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        _listArray = [NSMutableArray array];
        for (NSDictionary *dict in [dic objectForKey:@"msg"]) {
            M_L_Object *model = [[M_L_Object alloc] init];
            [model setValuesForKeysWithDictionary:dict];
            if ([model.M_L_Type isEqualToString:@"3"]) {
                [_listArray addObject:model];
            }
        }
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        // 解析失败隐藏系统风火轮(可以打印error.userInfo查看错误信息)
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self obtainData];
}

//设置单元格高度
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 100;
}


//设置表视图中的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _listArray.count;
}
//设置表视图中的section（分组）数,默认为1
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
// 设置header的高度


//设置单元格中的数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdent = @"AccountDetailsTableViewCell";
    AccountDetailsTableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:cellIdent];
    if (cell == nil) {
        cell = [[AccountDetailsTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
    }
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    M_L_Object *model = [_listArray objectAtIndex:indexPath.row];
    cell.subheadingLabel.text = [NSString stringWithFormat:@"交易类型：%@",model.M_L_Content];
    cell.titleLabel.text = [NSString stringWithFormat:@"交易时间：%@",model.M_L_AddTime];
    cell.betcutoffLabel.text = [NSString stringWithFormat:@"%@元",model.M_L_Money];
    cell.betcutoff2Label.text = [NSString stringWithFormat:@"%@元",model.M_L_AfterMoney];
    
    return cell;
}
//  设置组头


@end
